import { $C, $rp } from '@/utils/constants';

const noteP = $C.notifications.position;
const noteA = $C.notifications.action;

export default (note) => {
  const errs = ['其它提醒参数错误'];
  if (note.noteInfo.err) errs.push(note.noteInfo.msg);

  if (errs.length > 1) return { id: note.id, err: true, msg: errs.join(', ') };

  let [desc1, desc2, desc3, desc3Path, rootPath] = [];

  switch (note.noteInfo.action) {
    case noteA.admin:
      desc2 = '的管理员';
      if (note.noteInfo.position === noteP.space) {
        desc1 = '你已成为 空间';
        rootPath = `/${$rp.SPACES}/${note.noteInfo.id}`;
      } else if (note.noteInfo.position === noteP.group) {
        desc1 = '你已成为 群组';
        rootPath = `/${$rp.GROUPS}/${note.noteInfo.id}`;
      } else errs.push('位置参数 position 错误');
      break;
    case noteA.comment:
      if (note.noteInfo.position === noteP.feedback) {
        desc1 = '你的反馈';
        Object.assign(note.noteInfo, { title: note.noteInfo.title });
        rootPath = `/${$rp.FEEDBACK}/${note.noteInfo.id}`;
        desc2 = '有新回复';
      } else if (note.noteInfo.position === noteP.spaceApply) {
        desc1 = '空间';
        rootPath = `/${$rp.SPACES}/${note.noteInfo.spaceId}`;
        Object.assign(note.noteInfo, { title: note.noteInfo.spaceTitle });
        if (note.noteInfo.state === 1) desc2 = '的公开申请已经通过了';
        else if (note.noteInfo.state === 2) {
          desc2 = '的公开申请';
          desc3 = '被拒绝了';
          desc3Path = `/${$rp.APPLICATION_FOR_PUBLIC_SPACES}/${note.noteInfo.id}`;
        }
      } else errs.push('回复参数 position 错误');
      break;
    case noteA.invite:
      desc1 = '空间';
      rootPath = `/${$rp.SPACES}/${note.noteInfo.spaceId}`;
      Object.assign(note.noteInfo, { title: note.noteInfo.spaceTitle });
      desc2 = '收到了来自社区的邀请，';
      desc3 = '点击查看';
      desc3Path = `/${$rp.SPACES}/${note.noteInfo.spaceId}/${$rp.SETTINGS}?active=${$C.spaces.settings.communities}`;
      break;
    default: errs.push('未处理的 other 消息提醒');
  }

  if (errs.length > 1) return { id: note.id, err: true, msg: errs.join(', ') };
  return {
    id: note.id,
    type: note.type,
    desc1,
    desc2,
    desc3,
    desc3Path,
    root: { title: note.noteInfo.title, path: rootPath },

    read: note.read,
    created_at: note.created_at,
    updated_at: note.updated_at,
  };
};
